package tp.pr3.instructions;



import java.util.StringTokenizer;

import tp.pr3.NavigationModule;
import tp.pr3.RobotEngine;
import tp.pr3.instructions.exceptions.InstructionExecutionException;
import tp.pr3.instructions.exceptions.WrongInstructionFormatException;
import tp.pr3.items.ItemContainer;


public class HelpInstruction
extends java.lang.Object
implements Instruction {
	
    private RobotEngine r;
	
	public Instruction parse(java.lang.String cad)throws WrongInstructionFormatException
	{
		StringTokenizer instructionToken = new StringTokenizer(cad);
	if (instructionToken.countTokens() != 1)
		throw new WrongInstructionFormatException();
	
	String actionString = instructionToken.nextToken();	
	if(!(actionString.equalsIgnoreCase("HELP") || actionString.equalsIgnoreCase("AYUDA")))
		throw new WrongInstructionFormatException();
	
	return new HelpInstruction();		
	
	}
	
	public void execute()throws InstructionExecutionException
	{
		try{
			r.requestHelp();
			System.out.println("");
		}catch(Exception e){
			throw new InstructionExecutionException(e);
		}
	}
	
	public java.lang.String getHelp()
	{
	    return  ("HELP | AYUDA");		
	}
	
	public void configureContext(RobotEngine engine,
            NavigationModule navigation,
            ItemContainer robotContainer)
	{	
		r=engine;
	}
            

}
